{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "804fd41f",
   "metadata": {},
   "source": [
    "___\n",
    "* 2022.10.11\n",
    "___"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9cb437f4",
   "metadata": {},
   "source": [
    "## 本周内容\n",
    "> 1.代码的注释  \n",
    "> 2.用户输入  \n",
    "> 3.格式化输入"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "66b458ec",
   "metadata": {},
   "source": [
    "### 1.代码的注释\n",
    "> 1.# 一般写在代码块的最上边，或者每一行代码的最后，用于代码思路的记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "61dd353d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# sadaaf"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "faeacb8e",
   "metadata": {},
   "source": [
    "> 2.“注释内容”，一般是注释代码块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "889af272",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "三个引号注释代码块内容，不运行\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "dfghjkl\\\n",
    "gjk\n",
    "'''\n",
    "print(\"三个引号注释代码块内容，不运行\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49f21dea",
   "metadata": {},
   "source": [
    "### 2.用户输入\n",
    "> 1.input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c1bc998b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:An\n",
      "密码:123456\n",
      "An\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6f5e1329",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:An\n",
      "密码:123456\n",
      "欢迎An登录！\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统 1.增加了判断功能\n",
    "# 假设我们数据库有用户信息：账号:admin 密码：123456\n",
    "userl = \"An\"\n",
    "passwordl = \"123456\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "# 情景一：输入信息正确，登陆成功\n",
    "if userl == username and passwordl == password:\n",
    "    print(\"欢迎\"+userl+\"登录！\")\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "ab6ab9b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:a\n",
      "密码:a\n",
      "账号不存在或密码不正确\n",
      "您还有2次尝试机会\n",
      "账号:a\n",
      "密码:a\n",
      "账号不存在或密码不正确\n",
      "您还有1次尝试机会\n",
      "账号:a\n",
      "密码:a\n",
      "账号不存在或密码不正确\n",
      "您还有0次尝试机会\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统 2.增加循环功能\n",
    "# 假设我们数据库有用户信息：账号:admin 密码：123456\n",
    "userl = \"An\"\n",
    "passwordl = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号:\")\n",
    "    password = input(\"密码:\")\n",
    "\n",
    "    # 情景一：输入信息正确，登陆成功\n",
    "    if userl == username and passwordl == password:\n",
    "        print(\"欢迎\"+userl+\"登录！\")\n",
    "        break # 终止循环\n",
    "    # 情景二：账号不存在或密码不正确\n",
    "    else:\n",
    "        print(\"账号不存在或密码不正确\")\n",
    "        print(\"您还有\"+str(i-1)+\"次尝试机会\") # str强制将int转换成str"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e9cfd26",
   "metadata": {},
   "source": [
    "### 3.格式化输出\n",
    "> 1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "9198a607",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名:Bob\n",
      "年龄:18\n",
      "收入:5w\n",
      "地址:雅马哈\n",
      "星座：天马座\n",
      "-----INFO OF Bob------\n",
      "年龄:18\n",
      "收入:5w\n",
      "地址:雅马哈\n",
      "星座:天马座\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法一\n",
    "name = input(\"姓名:\")\n",
    "age = input(\"年龄:\")\n",
    "salary = input(\"收入:\")\n",
    "reg = input(\"地址:\")\n",
    "star = input(\"星座：\")\n",
    "\n",
    "info = '''-----INFO OF '''+ name +'''------'''+'''\n",
    "年龄:'''+age+'''\n",
    "收入:'''+salary+'''\n",
    "地址:'''+reg+'''\n",
    "星座:'''+star\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "461ed37b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "年龄:1\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "# input 作为用户输入，其都以字符串形式返回\n",
    "age = input(\"年龄:\")\n",
    "print(age,type(age))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "465b9f01",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名:Bob\n",
      "年龄:1\n",
      "收入:1w\n",
      "地址:GZ\n",
      "星座：哆啦A梦\n",
      "-----INFO OF Bob------\n",
      "年龄:1\n",
      "收入:1w\n",
      "地址:GZ\n",
      "星座:哆啦A梦\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法二：占位符 %s 依次有序输入\n",
    "name = input(\"姓名:\")\n",
    "age = int(input(\"年龄:\")) # 强制将str 转换成 int\n",
    "salary = input(\"收入:\")\n",
    "reg = input(\"地址:\")\n",
    "star = input(\"星座：\")\n",
    "\n",
    "info = '''-----INFO OF %s------\n",
    "年龄:%d\n",
    "收入:%s\n",
    "地址:%s\n",
    "星座:%s'''%(name,age,salary,reg,star)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "58b792c9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名:11\n",
      "年龄:12\n",
      "收入:111333\n",
      "地址:GZ\n",
      "星座：gz\n",
      "-----INFO OF 11------\n",
      "姓名:11\n",
      "年龄:12\n",
      "收入:111333\n",
      "地址:GZ\n",
      "星座:gz\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法三：format() 格式化输出函数\n",
    "name = input(\"姓名:\")\n",
    "age = int(input(\"年龄:\")) # 强制将str 转换成 int\n",
    "salary = input(\"收入:\")\n",
    "reg = input(\"地址:\")\n",
    "star = input(\"星座：\")\n",
    "\n",
    "info = '''-----INFO OF {姓名}------\n",
    "姓名:{姓名}\n",
    "年龄:{年龄}\n",
    "收入:{收入}\n",
    "地址:{地址}\n",
    "星座:{星座}'''.format(姓名=name,年龄=age,地址=reg,星座=star,收入=salary)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "67bfbb32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "余额:666元\n",
      "商品A\n",
      "商品B\n",
      "商品编号:A\n",
      "购买成功，余额：566元\n"
     ]
    }
   ],
   "source": [
    "# 支付系统\n",
    "Alipay = \"666元\"\n",
    "A = \"100元\"\n",
    "B = \"999元\"\n",
    "\n",
    "Alipaybalance = input(\"余额:\")\n",
    "\n",
    "if Alipay == Alipaybalance:\n",
    "    print(\"商品A\")\n",
    "    print(\"商品B\")\n",
    "\n",
    "ArticleNo = input(\"商品编号:\")\n",
    "\n",
    "if Alipay > A and Alipay < B:\n",
    "    print(\"购买成功，余额：566元\")\n",
    "else:\n",
    "    print(\"余额不足\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5cf83380",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
